<template>
  <div class="upload-container">
    <el-upload action="#" :http-request="upload">
      <el-button type="primary">点击上传</el-button>
      <template #tip>
        <div class="el-upload__tip">
          excel files with a size less than 500kb
        </div>
      </template>
    </el-upload>
  </div>

  <el-button class="backBtn" @click="$router.push('/map')">返回</el-button>
</template>
<script setup>
import { ElMessage } from 'element-plus'
import { uploadExcel } from '@/apis'
const upload = (res) => {
  console.log(res)
  try {
    const fd = new FormData()
    fd.append('file', res.file)
    uploadExcel(fd)
    ElMessage({
      message: '上传成功',
      type: 'success',
    })
  } catch (error) {
    console.log('上传失败', error)
  }
}
</script>

<style scoped>
.upload-container {
  width: 100wh;
  height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}
.backBtn {
  position: fixed;
  top: 10px;
  left: 10px;
}
</style>
